package com.market.manager;


import java.io.Serializable;
import java.util.List;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.market.domain.BaseObject;

/**
 * Generic Manager that talks to GenericDao to CRUD POJOs.
 *
 * <p>Extend this interface if you want typesafe (no casting necessary) managers
 * for your domain objects.
 *
 */
public interface GenericManager<BO extends BaseObject, PK extends Serializable> {
	

    /**
     *This method load all entities of specific type from database
     *This operation will only load basic properties, associated entities will not be load.
     */
	@Transactional(propagation = Propagation.REQUIRED,  readOnly=true )
    public List<BO> fetchAll();

    /**
     * This method will load basic properties and associated entities too.
     * 
     * @param id:specified entity
     * @return: the entity load from database.
     */
	@Transactional(propagation = Propagation.REQUIRED, readOnly=true)
	public BO fetchOne(PK id);
	
	 /**
     * This method will load basic properties and associated entities too.
     * 
     * @param bo:specified entity
     * @return: the entity load from database.
     */
	@Transactional(propagation = Propagation.REQUIRED, readOnly=true)
	public BO fetchOne(BO bo);

    /**
     * Checks for existence of an object of type T using the id arg.
     * @param id the identifier (primary key) of the object to get
     * @return - true if it exists, false if it doesn't
     */
	@Transactional(propagation = Propagation.REQUIRED, readOnly=true)
	public boolean check(PK id);

    /**
     * Generic method to save an object - handles insert and update
     * Object's isNew property will be set to false, if it is saved successfully into database.
     * @param object the object to save
     * @return the updated object
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class)
    public BO store(BO object);

    /**
     * Generic method to delete an object based on class and id
     * @param id the identifier (primary key) of the object to remove
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class)
    public void deleteById(PK id);
    
    /**
     * Generic method to delete an object based on class and id
     * @param id the identifier (primary key) of the object to remove
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor=RuntimeException.class)
    public void delete(BO object);

   
}
